1857D - Strong Vertices - CodeForces Solution


math sortings trees

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

/**----data type----*/
#define ll long long int
#define llu unsigned long long int

#define fast      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi          acos(-1.0)
#define nl          '\n'
/**-------Shortend Library-------*/
#define vi vector<int>
#define mii map<int, int>
#define f(i,n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<=b; i++)
#define testcase ll t;cin>>t;while(t--)

#define ff first
#define ss second
#define all(a)         a.begin(),a.end()
#define Sort(x)        sort(x.begin(),x.end())
#define SortR(x)       sort(x.begin(),x.end(),greater<int>())
#define Reverse(x)     reverse(x.begin(),x.end())

#define SortA(ar,s)    sort(ar,ar+s)
#define SortD(ar,s)    sort(ar,ar+s,greater<int>())

#define gcd(a,b)       __gcd(a,b)
#define lcm(a,b)       (a*(b/gcd(a,b)))
#define sq(x)          (x)*(x)
#define mid(l,r)       (l+(r-l)/2)

#define leftShift(p)         (p<<1)
#define rightShift(p)        (p>>1)

#define min3(a,b,c)       min(a,min(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max3(a,b,c)       max(a,max(b,c))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define pb(x)             push_back(x)
#define mod               1e8+7
#define precision(x)      cout<<fixed<<setprecision(x)
#define yes               cout<<"YES"<<nl
#define no                cout<<"NO"<<nl
#define min_heap priority_queue<ll,vector<ll>,greater<ll>>

/**----Functions to use----**/
ll powerLog(ll base, ll power)
{
    ll res = 1;
    while(power)
    {
        if(power%2)
        {
            res *= base;
            power--;
        } else 
        {
            base *=base;
            power/=2;
        }
    }
    return res;
}

void cholokori()
{
    ll n;
    cin>>n;
    vector<ll> a1, a2;
    for(int i=0; i<n; i++) {
        int num;
        cin>>num;
        a1.pb(num);
    }

    for(int i=0; i<n; i++) {
        int num;
        cin>>num;
        a2.pb(num);
    }
    vector<ll>diff(n, 0);
    for(int i=0; i<n; i++) {
        diff[i] = a1[i] - a2[i];
    }
    vector<pair<ll,ll>>vp;
    for(int i=0; i<n; i++) {
        vp.push_back({diff[i], i+1});
    }

    sort(all(vp), [&](pair<ll, ll>x, pair<ll,ll>y){
        if(x.ff==y.ff){
            return (x.ss<y.ss);
        }else{
            return (x.ff>y.ff);
        }
    });

    int maxm = vp[0].ff;
    vector<ll>ans;
    for(auto it:vp) {
        if(it.ff==maxm) {
            ans.pb(it.ss);
        }
    }

    cout<<ans.size()<<nl;
    for(auto it:ans) cout<<it<<' ';
    cout<<nl;
}

int main()
{
    testcase{
        cholokori();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training